package com.qf.web.controller;

import com.qf.domain.Stu;
import com.qf.service.StuService;
import com.qf.service.impl.StuServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * projectName:test_stu
 * author:lcy
 * time:2023/12/8 16:46
 * description:
 */
@WebServlet("/selectstuservlet")
public class SelectStuServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        StuService stuService=new StuServiceImp();
        try {
            List<Stu> stuList=stuService.findAll();
            System.out.println(stuList);
            request.setAttribute("stulist",stuList);
           request.getRequestDispatcher("selectStudent.jsp").forward(request, response);
        } catch (Exception e) {
            e.printStackTrace();
            request.setAttribute("msg", "查询失败" + e.getMessage());
            //return "message.jsp";
            request.getRequestDispatcher("message.jsp").forward(request, response);

        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}


